<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

JFX::checkAdminPermsRedirect('core', 'perm_edit_blocks');


$CONFIG->debug = true;


$VIEW->template = 'admin-thickbox.tpl';


$id = get('id');
$parentid = get('parent');
$blockid = $id;

$id = explode('-', $id);

if(count($id)<4){
    JFX::addError($this->lang('invalid_block_id'));
    return;
}

$params = array(
    'id' => $blockid,
    'page' => $id[1],
    'module' => $id[2],
    'instance' => $id[3],
    'workspace' => $USER->workspace,
    'lang' => $USER->lang
);

$block = new JFX_Block;
if(!$block->loadById($blockid)){
    $details = array(
        'id' => $blockid,
        'page_id' => $params['page'],
        'parent_id' => $parentid,
        'module_key' => $params['module'],
        'workspace_id' => $USER->workspace
    );
    $block->setDetails($details);
    $block->save();
    $block->loadById($id);
}

$params = array_merge($params, $block->getDetails());
$module = JFX::registry('JFX_Module_'.$params['module']);
$string = $module->updateSettings($params);

echo $string;


